﻿using UnityEngine;
using System.Collections;

public enum GridType
{
    None = 0,
    Road,
    Obstacle
}

public class GridScript 
{
    public int X { get; set; }
    public int Y { get; set; }

    //构造函数
    public GridScript(int x, int y)
    {
        this.X = x;
        this.Y = y;
    }

    //F,H,G
    public int F { get; set; }
    public int G { get; set; }
    public int H { get; set; }

    //计算F值
    private void CalF()
    {
        F = G + H;
        Debug.Log(F);
    }
    //计算H值
    private void CalH(GridScript target)
    {
        H = Mathf.Abs(target.X - X) + Mathf.Abs(target.Y - this.Y);
        H *= 10;
        CalF();
    }
    //计算G值
    public void CalG(GridScript parent, GridScript target)
    {
        int dir = Mathf.Abs(parent.X - this.X) + Mathf.Abs(parent.Y - this.Y);
        if (dir == 1)
            G = parent.G + 10;
        else
            G = parent.G + 14;
        //建立父子关系
        this.Parent = parent;
        Debug.Log(G);
        CalH(target);
    }
    //父节点
    public GridScript Parent { get; set; }

    public bool Visited { get; set; }

    public GridType gridType { get; set; }
}
